<template>
  <el-container>
    <el-header>
      <div>
        <img src="../assets/logo.png" alt="">
        <span>超市后台管理系统</span>
      </div>
      <el-button type="primary">退出</el-button>
    </el-header>
    <el-container>
<!--      左侧内容-->
<!--      <el-aside width="200px" style="background-color: rgb(238, 241, 246)">-->
<!--        <div class="expo">| | |</div>-->
<!--&lt;!&ndash;         :default-openeds="['1', '3']"一打开默认打开第一个和第三个&ndash;&gt;-->
<!--        <el-menu-->
<!--          :default-openeds="['1']"-->
<!--          background-color="#333"-->
<!--          text-color="#fff"-->
<!--          active-text-color="#409eff">-->
<!--          <el-submenu index="1">-->
<!--            <template #title><i class="el-icon-message"></i>导航一</template>-->
<!--            <el-menu-item-group>-->
<!--              <template #title>分组一</template>-->
<!--              <el-menu-item index="1-1">选项1</el-menu-item>-->
<!--              <el-menu-item index="1-2">选项2</el-menu-item>-->
<!--            </el-menu-item-group>-->
<!--            <el-menu-item-group title="分组2">-->
<!--              <el-menu-item index="1-3">选项3</el-menu-item>-->
<!--            </el-menu-item-group>-->
<!--            <el-submenu index="1-4">-->
<!--              <template #title>选项4</template>-->
<!--              <el-menu-item index="1-4-1">选项4-1</el-menu-item>-->
<!--            </el-submenu>-->
<!--          </el-submenu>-->
<!--          <el-submenu index="2">-->
<!--            <template #title><i class="el-icon-menu"></i>导航二</template>-->
<!--            <el-menu-item-group>-->
<!--              <template #title>分组一</template>-->
<!--              <el-menu-item index="2-1">选项1</el-menu-item>-->
<!--              <el-menu-item index="2-2">选项2</el-menu-item>-->
<!--            </el-menu-item-group>-->
<!--            <el-menu-item-group title="分组2">-->
<!--              <el-menu-item index="2-3">选项3</el-menu-item>-->
<!--            </el-menu-item-group>-->
<!--            <el-submenu index="2-4">-->
<!--              <template #title>选项4</template>-->
<!--              <el-menu-item index="2-4-1">选项4-1</el-menu-item>-->
<!--            </el-submenu>-->
<!--          </el-submenu>-->
<!--          <el-submenu index="3">-->
<!--            <template #title><i class="el-icon-setting"></i>导航三</template>-->
<!--            <el-menu-item index="3-1">选项1</el-menu-item>-->
<!--            <el-menu-item index="3-2">选项2</el-menu-item>-->
<!--          </el-submenu>-->
<!--        </el-menu>-->
<!--      </el-aside>
rgb(238, 241, 246)-->

      <el-aside  style="background-color: #333" :width="isCollapse?'65px':'250px'">
        <div class="expo" @click="isCollapse=!isCollapse">| | |</div>
        <!--         :default-openeds="['1', '3']"一打开默认打开第一个和第三个-->
<!--       @open="handlerOpen"
          @close="handleClose"
          class="el-menu-vertical"
            :default-openeds="['1']"-->
        <el-menu
          :unique-opened="true"
          :collapse="isCollapse"
          :collapse-transition="false"
          background-color="#333"
          text-color="#fff"
          active-text-color="#409eff"
          @open="handlerOpen"
          @close="handleClose"
          class="el-menu-vertical"
        >
          <el-submenu  v-for="(item,index) in menuList" :key="item.id" :index="item.id+''">
            <template #title>
              <i :class="iconArray[index]"></i>
              <span> {{item.authName}}</span>

            </template>
            <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id">
              <i class="el-icon-menu"></i>
              <span @click="toPath(subItem.path)"> {{subItem.authName}}</span>
            </el-menu-item>

          </el-submenu>
        </el-menu>
      </el-aside>

<!--      右侧内容-->
      <el-main>
<!--        因为左边点击一个，右边显示相应的所以应该是路由，应该是router-view,这个应该是home的子路由-->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
name: "home",
  data(){
    return{
      menuList:[],
      iconArray:['el-icon-user-solid','el-icon-s-tools','el-icon-s-goods','el-icon-s-order','el-icon-s-data'],
      isCollapse:false

    }
  },
  created() {//网页一加载自动执行
  this.getMenuList();
  },
  methods:{
    getMenuList(){
      this.axios.get('menus').then(data=>{//电商文档里面是menus的请求
        this.menuList=data.data.data;
      }).catch(err=>{
        console.log(err);
      })
    },
    handlerOpen(key,keyPath){
      console.log(key,keyPath);
    },
    handleClose(key,keyPath){
      console.log(key,keyPath);
    },
    toPath(path){
      this.$router.push(path);
    }
  }
}
</script>

<style scoped>
  .el-container{
    height: 100%;
  }
  .el-header{
    display: flex;
    color: #fff;
    background-color: #0f0f0f;
    /*左右两边对齐*/
    justify-content: space-between;
    padding-left: 10px;
    align-items: center;
    font-size: 24px;

  }
  .el-header div{
    display: flex;
    align-items: center;
  }
  .el-header div img{
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }
  .el-header div span {
    margin-left: 20px;
  }
  .expo{
    background: #4a5064;
    font-size: 10px;
    color: #fff;
    line-height: 24px;
    text-align: center;
    user-select: none;
    cursor: pointer;
  }

  .el-aside{
    background: #33333f;
    height: 100%;
  }
  .el-main{
    background-color: #fff;
  }
</style>
